<?php

namespace app\adminapi\controller\v2;

use app\adminapi\controller\AuthController;

class Index extends AuthController
{
    public function index()
    {
        // 企业
        // 今日
        $company_today = \app\model\company\Company::where('status', 1)
            ->count();
        // 昨日
        $company_yesterday = \app\model\company\Company::where('status', 1)
            ->whereBetween('create_time', [
                strtotime('yesterday 00:00:00'),
                strtotime('yesterday 23:59:59')
            ])
            ->count();
        // 本月
        $company_total = \app\model\company\Company::where('status', 1)
            ->whereBetween('create_time', [
                strtotime(date('Y-m-01')),
                strtotime('first day of next month') - 1
            ])
            ->count();

        // 教师
        // 今日
        $teacher_today = \app\model\teacher\Teacher::where('status', 1)
            ->count();
        // 昨日
        $teacher_yesterday = \app\model\teacher\Teacher::where('status', 1)
            ->whereBetween('create_time', [
                strtotime('yesterday 00:00:00'),
                strtotime('yesterday 23:59:59')
            ])
            ->count();
        // 本月
        $teacher_total = \app\model\teacher\Teacher::where('status', 1)
            ->whereBetween('create_time', [
                strtotime(date('Y-m-01')),
                strtotime('first day of next month') - 1
            ])
            ->count();

        // 课件
        // 今日
        $ware_today = \app\model\course\ware\Courseware::where('status', 1)
            ->count();
        // 昨日
        $ware_yesterday = \app\model\course\ware\Courseware::where('status', 1)
            ->whereBetween('create_time', [
                strtotime('yesterday 00:00:00'),
                strtotime('yesterday 23:59:59')
            ])
            ->count();
        // 本月
        $ware_total = \app\model\course\ware\Courseware::where('status', 1)
            ->whereBetween('create_time', [
                strtotime(date('Y-m-01')),
                strtotime('first day of next month') - 1
            ])
            ->count();

        return app('json')->success([
                'data' => [[
                    'title' => '企业总数',
                    'date' => '今日',
                    'today' => $company_today,
                    'yesterday' => $company_yesterday,
                    'total_name' => '本月新增',
                    'total' => $company_total,
                ], [
                    'title' => '教师总数',
                    'date' => '今日',
                    'today' => $teacher_today,
                    'yesterday' => $teacher_yesterday,
                    'total_name' => '本月新增',
                    'total' => $teacher_total,
                ], [
                    'title' => '课件总数',
                    'date' => '今日',
                    'today' => $ware_today,
                    'yesterday' => $ware_yesterday,
                    'total_name' => '本月新增',
                    'total' => $ware_total,
                ]
                ]]
        );
    }
}